package creation.property;

import java.io.*;
import java.util.Date;

public class Video implements Cloneable,Serializable{
    private String name;
    private Date data;

    public Video(String name, Date data) {
        this.name = name;
        this.data = data;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        var obj = (Video) super.clone();
        obj.data = (Date) data.clone();
        return  obj;
    }

    protected Object deepClone()  {

        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;

        ByteArrayInputStream bis = null;
        ObjectInputStream ois = null;
        Object obj = null;
        try {
            //序列化
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(this);

            //反序列化
            bis = new ByteArrayInputStream(bos.toByteArray());
            ois = new ObjectInputStream(bis);
            obj = ois.readObject();

        }catch (Exception e){
            System.out.println(e);
        }finally {
            try {
                bos.close();
                oos.close();
                bis.close();
                ois.close();
            }catch (Exception e){
                System.out.println(e);
            }
        }


        return  obj;
    }

    public void setData(Date data) {
        this.data = data;
    }
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Video{" +
                "name='" + name + '\'' +
                ", data=" + data +
                '}';
    }
}
